import request from '../../utils/request';

export interface ProcessDefinitionVO {
  id: string;
  version: number;
  deploymentTime: string;
  suspensionState: number;
  formType?: number;
}

export interface ModelVO {
  id: number;
  formName: string;
  key: string;
  name: string;
  description: string;
  category: string;
  formType: number;
  formId: number;
  formCustomCreatePath: string;
  formCustomViewPath: string;
  processDefinition: ProcessDefinitionVO;
  status: number;
  remark: string;
  createTime: string;
  bpmnXml: string;
}

// BPM 模型管理 API
export const ModelApi = {
  // 查询模型列表
  getModelList: async (name?: string) => {
    return await request.get('/bpm/model/list', { params: { name } });
  },

  // 查询模型详情
  getModel: async (id: string) => {
    return await request.get(`/bpm/model/get?id=${id}`);
  },

  // 更新模型
  updateModel: async (data: ModelVO) => {
    return await request.put('/bpm/model/update', data);
  },

  // 批量修改模型排序
  updateModelSortBatch: async (ids: number[]) => {
    return await request.put('/bpm/model/update-sort-batch', {
      params: { ids: ids.join(',') }
    });
  },

  // 更新模型 BPMN
  updateModelBpmn: async (data: ModelVO) => {
    return await request.put('/bpm/model/update-bpmn', data);
  },

  // 更新模型状态
  updateModelState: async (id: number, state: number) => {
    return await request.put('/bpm/model/update-state', { id, state });
  },

  // 创建模型
  createModel: async (data: ModelVO) => {
    return await request.post('/bpm/model/create', data);
  },

  // 删除模型
  deleteModel: async (id: number) => {
    return await request.delete(`/bpm/model/delete?id=${id}`);
  },

  // 部署模型
  deployModel: async (id: number) => {
    return await request.post(`/bpm/model/deploy?id=${id}`);
  },

  // 清理模型
  cleanModel: async (id: number) => {
    return await request.delete(`/bpm/model/clean?id=${id}`);
  }
};